#include "list.h"



unsigned char list_search(list_t * plist, unsigned char value)
{
	unsigned char i = 0;
	
	if(plist && (plist->length < plist->compacity))
	{
		while((i<plist->length) && (plist->pbuffer[i] != value))
		{
			i++;
		}
	}
	return i;
}

void list_insert(list_t * plist, unsigned char index, unsigned char value)
{
	unsigned char i;
	
	if(plist && (plist->length < plist->compacity))
	{
		if(index > plist->length)
		{
			index = plist->length;
		}
		for(i=plist->length;i>index;i--)
		{
			plist->pbuffer[i] = plist->pbuffer[i-1];
		}
		plist->pbuffer[index] = value;
		plist->length++;
	}
}

void list_remove(list_t * plist, unsigned char index)
{
	unsigned char i;
	
	if(plist && (plist->length > 0))
	{
		if(index > plist->length)
		{
			index = plist->length - 1;
		}
		for(i=index;i<plist->length;i++)
		{
			plist->pbuffer[i] = plist->pbuffer[i+1];
		}
		plist->length--;
	}
}